<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>文件上传下载测试</title>
</head>
<body>
<div class="container-fluid" style="margin-top: 20px;">
    <div class="row">
        <div class="col-md-6">
            <div class="form-inline">
                选择文件: <input type="file" name="file" id="file" class="form-control">
            </div>
            <div class="form-inline" style="margin-top: 20px;">
                <a class="btn btn-success btn-sm" onclick="uploadFile(1)">上传($_FILES)</a>
                <a class="btn btn-success btn-sm" onclick="uploadFile(2)">上传(getUploadedFiles)</a>
                <a class="btn btn-success btn-sm" onclick="uploadFile(3)">上传(filePath)</a>
            </div>
        </div>
        <div class="col-md-6" id="result">

        </div>
    </div>
</div>

<script>
    function uploadFile(type) {
        var file = document.getElementById('file').files[0];
        var data = new FormData();
        data.append('file', file);
        data.append('type', type);
        $.ajax({
            url: '/help/uploadFile',
            type: 'POST',
            processData: false,
            contentType: false,
            data: data,
            complete: function (XMLHttpRequest) {
                var result = XMLHttpRequest.responseJSON;
                var dom = $('#result');
                dom.append('<p>上传到mongo成功</p>')
                $.each(result, function (key, value) {
                    dom.append(`<p>键：${key}，值：${value}<p>`);
                })
            }
        });
//        axios({
//            method: 'post',
//            url: '/help/uploadFile',
//            data: data,
//        }).then(function (response){
//            var dom = $('#result');
//            dom.append('<p>上传到mongo成功</p>')
//            $.each(response.data, function (key, value) {
//                dom.append(`<p>键：${key}，值：${value}<p>`);
//            })
//        }).catch(function (error) {
//            console.log(error);
//        });
    }
</script>
</body>
</html>